const getData = () => new Promise((resolve, reject) => {
    setTimeout(() => {
        const num = Math.floor(Math.random() * 520)
        resolve(num)
    }, 1000)
})

function asyncFuncInvoke(gen) {
    const iter = gen()
   
    function walk(data){
        let temp = iter.next(data)
        // console.log(temp);
        if(temp.done) {
            console.log(temp);
            
            return temp
        }
        temp.value.then(data=>walk(data)).catch(err=>iter.throw(err))
    }

    walk()
    

}

function* test() {
    try {
        const num1 = yield getData()
        console.log(num1)
        const num2 = yield getData()
        console.log(num2)
        const num3 = yield getData()
        console.log(num3)
    } catch (error) {
        console.log('the erro is '+error);
    }

    return 'OK'
}

console.log(typeof asyncFuncInvoke(test));




